/**
 * @lastUpdateBy : 韩怡婷
 * @description: image分组管理相关api
 */
import qs from 'qs'; // 导入qs模块 增加了一些安全性的查询字符串解析和序列化字符串的库
export default {
    /**
     * @description: 根据自编码获取可视数据目录树
     * @param {Object} params 参数
     * @return {Promise}
     */
    treeByCode(params) {
        return new Promise((resolve, reject) => {
            agcim.net.axiosWraper
                .getData(
                    agcim.net.apiPath.io_dirimagestore_treeByCode,
                    params
                )
                .then(
                    (response) => {
                        if (response.success) {
                            resolve(response);
                        } else {
                            reject(response);
                        }
                    },
                    (error) => {
                        reject(error);
                    }
                );
        });
    },


    /**
     * @description: 新增分组
     * @param {Object} params
     * @return {Promise}
     */
    addDirImage(params) {
        return new Promise((resolve, reject) => {
            agcim.net.axiosWraper
                .getDataByPost(
                    agcim.net.apiPath.io_dirimagestore_addDirImage,
                    qs.stringify(params)
                )
                .then(
                    (response) => {
                        if (response.success) {
                            resolve(response);
                        } else {
                            reject(response);
                        }
                    },
                    (error) => {
                        reject(error);
                    }
                );
        });
    },


    /**
     * @description: 更新
     * @param {Object} params
     * @return {Promise}
     */
    updateDirImage(params) {
        return new Promise((resolve, reject) => {
            agcim.net.axiosWraper
                .getDataByPost(
                    agcim.net.apiPath.io_dirimagestore_updateDirImage,
                    qs.stringify(params)
                )
                .then(
                    (response) => {
                        if (response.success) {
                            resolve(response);
                        } else {
                            reject(response);
                        }
                    },
                    (error) => {
                        reject(error);
                    }
                );
        });
    },


    /**
     * 删除单个分组 不支持删除非空分组 暂时没有用到
     * @param {Object} params 
     * @returns {Promise}
     */
    deleteDirImage(params) {
        return new Promise((resolve, reject) => {
            agcim.net.axiosWraper
                .delete(agcim.net.apiPath.io_dirimagestore_deleteDirImage, params)
                .then(
                    (response) => {
                        if (response.success) {
                            resolve(response);
                        } else {
                            reject(response);
                        }
                    },
                    (error) => {
                        reject(error);
                    }
                );
        });
    },
    /**
     * 拖拽排序
     * @param {Object} params 
     * @returns {Promise}
     */
    dirDragSort(params) {
        return new Promise((resolve, reject) => {
            agcim.net.axiosWraper
                .getDataByPost(agcim.net.apiPath.io_dirimagestore_dirDragSort, params)
                .then(
                    (response) => {
                        if (response.success) {
                            resolve(response);
                        } else {
                            reject(response);
                        }
                    },
                    (error) => {
                        reject(error);
                    }
                );
        });
    },
    /**
     * 删除多个
     * @param {Object} params 
     * @returns {Promise}
     */
     deleteCascadeList(params) {
        return new Promise((resolve, reject) => {
            agcim.net.axiosWraper
                .delete(agcim.net.apiPath.io_dirimagestore_deleteCascadeList+"?id="+params, )
                .then(
                    (response) => {
                        if (response.success) {
                            resolve(response);
                        } else {
                            reject(response);
                        }
                    },
                    (error) => {
                        reject(error);
                    }
                );
        });
    },
};
